<!-- 最新调剂 -->
<template>
	<view class="pages">
		<view class="newIndex">
			<view v-if="!isNameSerch">
				<view class="contents">
					<view class="searchs">
						<view class="search-box">
							<view class="input-box flex" @click="handleNameSerch">
								<uni-icons type="search" size="20" color="#000" style="margin:0 10rpx"></uni-icons>
								<view class="font14" :class="majorNames?'color333':'color999'"> {{ majorNames || '输入学校/专业/代码,搜索官网调剂信息'}}
								</view>
							</view>
						</view>
						<view class="other-box flex alignCenter">
							<view class="search-select flex alignCenter" @click="handlePopup(1)">
								<view class="font12 bold" :class="year?'font14 select-item':''">{{year || '年份'}} </view>
								<uni-icons type="bottom" size="14" :color="year?'#F7DD5E':'#000'"
									style="margin-left: 10rpx;"></uni-icons>
							</view>

							<view class="search-select flex alignCenter" @click="handlePopup(2)">
								<view class="font12 bold" :class="arreaName?'font14 select-item':''">{{arreaName || '省份'}} </view>
								<uni-icons type="bottom" size="14" :color="arreaName?'#F7DD5E':'#000'"
									style="margin-left: 10rpx;"></uni-icons>
							</view>
							<view class="search-select flex alignCenter" @click="handlePopup(3)">
								<view class="font12 bold" :class="studyName?'font14 select-item':''">{{studyName || '学习形式'}} </view>
								<uni-icons type="bottom" size="14" :color="studyName?'#F7DD5E':'#000'"
									style="margin-left: 10rpx;"></uni-icons>
							</view>
							<!-- 	<view class="search-select font12 bold flex alignCenter">
							<uni-icons type="list" size="14" color="#000" style="margin-left: 4rpx;"></uni-icons>
						</view> -->
						</view>
					</view>
					<view class="u-p-b-40 u-p-l-30 u-p-r-30">
						<button @click="tiaozhuan" v-if="false">购买解锁列表</button>
						<!-- 调剂vip -->
						<view class="pay-vip flex alignCenter" v-if="!isVip">
							<view class="flex font14 alignCenter">
								<image class="icon" src="/pages/school/static/icon.png" mode="widthFix"></image>
								<view class="font14 color333 txt">调剂VIP，最新调剂信息第一时间掌握，成功率提升N倍</view>
							</view>
							<view class="button font12 flex alignCenter" @click="handleLock">解锁VIP</view>
						</view>
						<!-- 列表数据 -->
						<view class="lists">
							<view class="content-item" v-for="(item,index) of schoolList" :key="item.id">
								<!-- 学校专业信息 -->
								<view class="school-item">
									<view class="top-title flex alignCenter">
										<!-- <image :src="item.imageUrl" mode="widthFix"></image> -->
										<view class="flex alignCenter">
											<image :src="item.schoolImg" mode="widthFix"></image>
											<view class="schoolName font16 bold">{{item.school}}接收调剂</view>
										</view>
										<view class="font12 font1333" @click="handleUrl(item.announcementAddress)">官网公告 > </view>
									</view>
									<view class="bottom-major flex ">
										<view class="font14">{{item.majorCode}} {{item.major}}（{{item.studyType==1?'全日制':'非全日制'}}）</view>
										<view class="font14 bold hot flex">
											<image src="/static/image/index/hot.png" mode="widthFix"></image> {{item.hot}}
										</view>
									</view>
								</view>

								<!-- 调剂信息 -->
								<view class="tiaoji-item font14 color333">
									<view class="flex flexWrap">
										<view>计划调剂人数：{{item.isLock?item.planAdjustQuantity || 0:''}}
											<image @click="handleLockItem(item)" v-if="!item.isLock" mode="widthFix"
												src="/static/image/toolbox/isLock.png"></image>
										</view>
										<view class="right-view">最新调剂余额：{{item.isLock?item.adjustBalance || 0:''}}
											<image @click="handleLockItem(item)" v-if="!item.isLock" mode="widthFix"
												src="/static/image/toolbox/isLock.png"></image>
										</view>
									</view>
									<view class="flex flexWrap">
										<view>实际调剂人数：{{item.isLock?item.adjustActualNum || 0:''}}
											<image @click="handleLockItem(item)" v-if="!item.isLock" mode="widthFix"
												src="/static/image/toolbox/isLock.png"></image>
										</view>
										<view class="right-view">其中校内调剂数：{{item.isLock?item.sameSchoolAdjustCount || 0:''}}
											<image @click="handleLockItem(item)" v-if="!item.isLock" mode="widthFix"
												src="/static/image/toolbox/isLock.png"></image>
										</view>
									</view>
								</view>

								<view class="font12 date">发布时间： {{item.year}}</view>
							</view>
							<view style="height: 50rpx;"></view>
						</view>
					</view>
					<view v-if="schoolList.length>=total" class="font12 noMore-data"> - 没有更多数据了 - </view>
				</view>
			</view>
			<view class="serchPage" v-else>
				<view class="contents">
					<view class="searchs">
						<view class="search-box flex alignCenter">
							<view class="input-box flex">
								<uni-icons type="search" size="20" color="#000" style="margin:0 10rpx"></uni-icons>
								<input class="font14" placeholder="输入学校/专业/代码,搜索官网调剂信息" v-model="title" @input="handleChange" />
								<uni-icons type="clear" @click="title=''" size="18"
									:color="title.length>0?'#F7DD5E':'#fff'"></uni-icons>
							</view>
							<view class="font12" @click="handleCancelSerch">取消</view>
						</view>
					</view>

					<view class="list">
						<view class="font16 bold color333 title"> 搜索结果 </view>
						<view class="font16 item" v-for="(item,index) of queryMajorS" :key="index" @click="serchSure(item)">
							{{item.schoolName||''}}{{item.majorName||''}}（{{item.schoolCode||''}} {{item.majorCode||''}}）
						</view>
					</view>
				</view>
			</view>

			<!-- 购买vip弹窗 -->
			<u-popup v-mode="searchPopup" mode="bottom" :mask-close-able="false">
				<view class="popup-box">
					<view class="flex btns">
						<view class="font14 cancel" @click="handleCancel">取消</view>
						<view class="font14 sure" @click="handleSure">确认</view>
					</view>
					<view class="search-contents" :class="popType == 4?'search-contents-more':''">
						<!-- 年份 -->
						<view v-if="popType == 1">
							<view v-for="(item,index) in yearList" :key="index" :class="index==yearIndex?'chooseItem':''"
								@click="yearIndex = index">{{item}}</view>
						</view>
						<!-- 省份 -->
						<view v-if="popType == 2">
							<view v-for="(item,index) in options" :class="index==optionsIndex?'chooseItem':''" :key="index"
								@click="optionsIndex = index">{{item.fullName}}</view>
						</view>
						<!-- 学习形式 -->
						<view v-if="popType == 3">
							<view v-for="(item,index) in studyOptions" :key="index" :class="index==studyIndex?'chooseItem':''"
								@click="studyIndex = index">{{item.name}}</view>
						</view>
					</view>
				</view>
			</u-popup>
		</view>
		<u-back-top :z-index="100" :scroll-top="scrollTop"></u-back-top>
	</view>
</template>

<script>
	import {
		addMyContrast
	} from "@/api/index.js"
	import {
		getAdjustDetailNew,
		selectList,
		getCityList,
		isBuyAdjustVip,
		fuzzyQueryMajor
	} from "@/api/toolbox.js"

	export default {
		data() {
			return {
				searchPopup: false,
				scrollTop: 0,
				title: "", //输入框搜索
				majorNames: '', //学校专业搜索结果值
				queryMajorS: [], //学校专业数组
				isNameSerch: false, //是否搜索
				isVip: false, //是否vip  true 为是，false为否
				options: [],
				options1: [],
				schoolClassifyOptions: [],
				popType: 1,
				total: 0,
				arreaName: '', //省份

				option1Name: '',
				classFyName: '',
				optionsIndex: '', //省份选择
				options1Index: '', //学校层次选择
				classFyIndex: '', //学校类型选择
				studyOptions: [{
						id: '',
						name: '全部'
					},
					{
						id: '1',
						name: '全日制'
					},
					{
						id: '2',
						name: '非全日制'
					},
				],
				studyIndex: 0,
				studyName: '', //学习形式
				yearList: [2024, 2023, 2022, 2021],
				year: '',
				yearIndex: 0,
				searchParam: {
					year: '', //年份
					province: "", //省份
					studyType: '', //学习形式
					pageNum: 1,
					pageSize: 10,
					reasonable: true,
					schoolCode: '',
					majorCode: '',
					// schoolClassify: "",//学习类型
					// schoolType: "",//学习层次
					//
					isKwkd: true,
				},
				schoolList: [],
				subjectStarOptions: [], //学科星级
				subjectStarOptions1: [], //一级学科星级
				subjectStarOptions2: [], //专业星级
			}
		},
		onLoad() {
			this.getOnShow();
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			this.getData('more');
		},
		//底部刷新
		methods: {
			tiaozhuan() {
				uni.navigateTo({
					url: "jiesuo1"
				})
			},
			getOnShow() {
				this.isNameSerch = false;
				this.title = '';
				this.getBuyAdjustVip()
				if (uni.getStorageSync('province')) {
					this.options = JSON.parse(uni.getStorageSync('province'));
					this.options.unshift({
						fullName: '全部',
						id: ''
					});
				} else {
					this.getOptions();
				}
				this.getData();
			},
			// 判断是否购买过vip
			getBuyAdjustVip() {
				isBuyAdjustVip().then(res => {
					if (res.code == 100000) {
						this.isVip = res.data;
						console.log('this.isVip: ', this.isVip);
					}
				})
			},
			// 输入框搜索
			handleNameSerch() {
				this.isNameSerch = true;
			},
			// 学校专业模糊检索
			handleChange() {
				fuzzyQueryMajor({
					'fuzzyMajorStr': this.title
				}).then(res => {
					console.log(res)
					if (res.code == 100000) {
						this.queryMajorS = res.data
					}
				})
			},
			// 取消学校专业模糊检索
			handleCancelSerch() {
				this.isNameSerch = false;
				this.title = '';
				// this.majorNames = '';
			},
			// 确认选择
			serchSure(item) {
				this.isNameSerch = false;
				this.searchParam.schoolCode = item.schoolCode ? item.schoolCode : '';
				this.searchParam.majorCode = item.majorCode ? item.majorCode : '';
				this.majorNames = item.schoolName ? item.schoolName : '' + " " + item.majorName ? item.majorName : '';
				this.handleSearch();
			},
			handleSearch() {
				this.searchParam.pageNum = 1;
				this.total = 1;
				// this.schoolList = [];
				this.getData();
			},
			handleClear() {
				this.searchParam.title = '';
				this.handleSearch();
			},
			getOptions() {
				// 获取省份
				getCityList().then((res) => {
					this.options = res.data;
					uni.setStorageSync('province', JSON.stringify(res.data));
					this.options.unshift({
						fullName: '全部',
						id: ''
					});
				});
			},
			/**
			 * @param {Object} type 1、年份,2、省份,3、学习形式,4、更多
			 */
			handlePopup(type) {
				// 判断是否买过vip,vip才可以搜索
				if (this.isVip) {
					this.popType = type;
					this.searchPopup = true;
					return
				}
				uni.showToast({
					title: 'VIP才能使用该功能哦~',
					icon: 'none',
					mask: true
				});
				setTimeout(() => {
					uni.navigateTo({
						url: `/pages/toolbox/adjustReport/adjustInfo`,
					})
				}, 1500)
			},
			// 立即解锁
			handleLock() {
				uni.navigateTo({
					url: `/pages/toolbox/adjustReport/adjustInfo`
				})
			},
			// 搜索弹框确认按钮
			handleSure() {
				// 年份
				if (this.popType == 1) {
					this.year = this.yearList[this.yearIndex];
					if (this.yearIndex == 0) {
						this.year = '';
					}
					this.searchParam.year = this.yearList[this.yearIndex];
				}
				// 省份
				if (this.popType == 2) {
					this.arreaName = this.options[this.optionsIndex].fullName;
					if (this.optionsIndex == 0) {
						this.arreaName = '';
					}
					this.searchParam.province = this.options[this.optionsIndex].fullName;
				}
				// 学习形式
				if (this.popType == 3) {
					this.studyName = this.studyOptions[this.studyIndex].name;
					if (this.studyIndex == 0) {
						this.studyName = '';
					}
					this.searchParam.studyType = this.studyOptions[this.studyIndex].id;
				}
				// 更多
				if (this.popType == 4) {
					// this.searchParam.subjectStar = this.subjectStarOptions[this.startIndex].dictValue;//学科星级
					// this.searchParam.subjectOneStar = this.subjectStarOptions1[this.startIndex1].dictValue;//一级学科星级
					// this.searchParam.majorStar = this.subjectStarOptions2[this.startIndex2].dictValue;//专业星级
					// this.searchParam.schoolType = this.options1[this.options1Index].dictValue;//层次
					// this.searchParam.examList = this.examList1.concat(this.examList2);//数学、英语偏好
				}
				this.searchPopup = false;
				this.handleSearch();
			},
			// 搜索弹框取消按钮
			handleCancel() {
				this.optionsIndex = '-1';
				this.studyIndex = '-1';
				this.yearIndex = '-1';
				// this.options1Index = '-1'; 
				// this.classFyIndex = '-1';
				this.searchPopup = false;
			},

			getData(type) {
				uni.showLoading({
					title: '数据加载中'
				})
				if (type == 'more') {
					if (this.schoolList.length >= this.total) {
						uni.hideLoading()
						return
					}
					this.searchParam.pageNum++;
				}
				getAdjustDetailNew(this.searchParam).then((res) => {
					uni.hideLoading()
					if (res.code == 100000) {
						res.data.rows.forEach(e => {})
						if (this.searchParam.pageNum == 1) {
							this.schoolList = res.data.rows;
							this.total = res.data.total;
							return
						}
						this.schoolList.push.apply(this.schoolList, res.data.rows);
					}
				}).catch(() => {
					uni.hideLoading()
				})
			},
			// 官网公告
			handleUrl(url) {
				uni.navigateTo({
					url: `/pages/toolbox/webview/webview?src=${url}`
				})
			},
			// 数据解锁
			handleLockItem(item) {
				let option = {
					schoolCode: item.schoolCode,
					collegeCode: item.collegeCode,
					majorCode: item.majorCode
				};
				uni.navigateTo({
					url: `/pages/toolbox/adjustReport/jiesuo1?items=${JSON.stringify(option)}`
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.pages {
		background: rgb(235, 238, 239);
		min-height: 100vh;
	}

	.newIndex {
		background: #f2f2f2;

		.contents {
			.searchs {
				padding-left: 30rpx;
				padding-right: 30rpx;
				padding-top: 20rpx;
				background-color: rgb(235, 238, 239);
				padding-bottom: 20rpx;
				position: sticky;
				top: 0rpx;
				/* #ifdef H5 */
				top: 80rpx;
				/* #endif */
				z-index: 2;

				.search-box {
					.input-box {
						background: #fff;
						height: 70rpx;
						border-radius: 40rpx;
						align-items: center;

						input {
							width: 100%;
						}
					}
				}

				.other-box {
					background: #ffffff;
					border-radius: 14rpx;
					margin-top: 20rpx;
					height: 70rpx;
					justify-content: space-around;

					.search-select {
						color: #666666;
						text-align: center;
					}

					.select-item {
						color: #F7DD5E;
					}
				}
			}

			.report-demo {
				justify-content: space-between;
				height: 128rpx;
				width: 100%;
				background: #333333;
				color: #FED534;

				.button {
					color: #333;
					background: #FED534;
				}
			}

			.pay-vip {
				margin-top: 24rpx;
				justify-content: space-between;
				width: 100%;
				height: 120rpx;
				background: #FED534;

				.button {
					color: #FED534;
					background: #333333;
				}
			}

			.report-demo,
			.pay-vip {
				border-radius: 16rpx;
				width: 100%;

				.icon {
					width: 36rpx;
					height: 48rpx;
					margin: 0 20rpx 0 28rpx;
				}

				.button {
					width: 67px;
					height: 30px;
					border-radius: 52rpx;
					justify-content: center;
					margin-right: 20rpx;
				}

				.txt {
					width: 420rpx;
				}
			}

			.lists {
				padding-top: 24rpx;

				.content-item {
					line-height: 1rem;
					background: #ffffff;
					margin-bottom: 20rpx;
					border-radius: 20rpx;
					box-shadow: 0 0 12rpx rgba(0, 0, 0, .2);
					padding-bottom: 70rpx;
					padding: 0 24rpx 0 28rpx;

					.school-item {
						padding-top: 20rpx;
						line-height: 1rem;
						border-bottom: 1px solid #D7D7D7;

						.top-title {
							justify-content: space-between;

							image {
								width: 60rpx;
								height: 60rpx;
								border-radius: 50%;
								margin-right: 10rpx;
							}

							.schoolName {
								width: 400rpx;
								line-height: 40rpx;
							}
						}

						.bottom-major {
							margin: 16rpx 0 20rpx;
							margin-left: 70rpx;
							justify-content: space-between;
						}

						.hot {
							color: #FF7101;

							image {
								width: 24rpx;
								height: 28rpx;
								margin-right: 2rpx;
							}
						}
					}

					.tiaoji-item {
						margin-top: 36rpx;

						>view {
							justify-content: space-between;
							margin-bottom: 32rpx;

							image {
								width: 30rpx;
								height: 30rpx;
							}

							.right-view {
								margin-right: 30rpx;
							}
						}
					}

					.date {
						color: #AAAAAA;
						padding: 12rpx 0 44rpx 0;
					}

				}
			}


		}

		.serchPage {
			.input-box {
				width: 90%;
				margin-right: 10rpx;
			}

			.list {
				.title {
					margin: 20rpx 0;
				}

				.item {
					line-height: 60rpx;
				}
			}
		}

		.noMore-data {
			text-align: center;
			color: #afafaf;
			padding-bottom: 20rpx;
		}

		.vip-popup {
			width: 600rpx;
			height: 446rpx;
			border-radius: 40rpx;
			background: #fff;
			text-align: center;

			// margin: auto;
			>image {
				margin-top: 40rpx;
				width: 160rpx;
				height: 160rpx;
			}

			.txt {
				lin-height: 1rem;
				margin: 20rpx 0 40rpx;
			}

			.buy-btn {
				width: 400rpx;
				height: 96rpx;
				background: #F7DD5E;
				border-radius: 60rpx;
				justify-content: center;
				margin: auto;

				image {
					width: 28rpx;
					height: 36rpx;
					margin-right: 26rpx
				}
			}
		}

		.close {
			width: 100rpx;
			height: 100rpx;
			background: #fff;
			border-radius: 50%;
			justify-content: center;
			margin: auto;
			margin-top: 44rpx;
		}

		.popup-box {
			background: #fff;
			border-top-left-radius: 30rpx;
			border-top-right-radius: 30rpx;
			padding: 30rpx;

			.btns {
				align-items: center;
				justify-content: space-between;
				margin: 10rpx 0;

				.cancel {
					color: #AFAFAF;
				}

				.sure {
					color: #F7DD5E;
				}
			}

			.search-contents {
				text-align: center;
				line-height: 70rpx;
				overflow-x: hidden;
				height: 500rpx;
				// background: #F7DD5E;

				.chooseItem {
					background-color: rgba(253, 224, 128, 0.3);
				}
			}

		}
	}
</style>